package math.region;

import math.math;
import math.vec3;

public class Line3 implements Curve3
{
    
    public vec3 mOrig;
    
    public vec3 mDir;
    
    
    public Line3()
    {
        this.mOrig = new vec3();
        this.mDir = new vec3();
    }
    
    public Line3(
            vec3 aOrig, 
            vec3 aDir)
    {
        this();
        this.set(aOrig, aDir);
    }
    
    
    public final void set(
            vec3 aOrig, 
            vec3 aDir)
    {
        this.mOrig.set(aOrig);
        this.setDir(aDir);
    }
    
    public final void set(Line3 aOther)
    {
        this.set(aOther.mOrig, aOther.mDir);
    }
    
    public final void setDir(vec3 aDir)
    {
        this.mDir.set(aDir);
        this.mDir.norm();
    }
    
    
    public boolean onCurve(vec3 aPoint)
    {
        vec3 localToPt = vec3.sub(aPoint, this.mOrig);
        localToPt.norm();
        double dot = localToPt.dot(this.mDir);
        boolean contains = math.abs(math.abs(dot) - 1.0) < math.EPSILON;
        return contains;
    }
    
    
    public vec3 point(double aT)
    {
        return vec3.add(this.mOrig, vec3.mul(this.mDir, aT));
    }
    
    
    public Line3 copy()
    {
        Line3 copy = new Line3();
        copy.set(this);
        return copy;
    }
    
    
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("Line3\n   Orig: ");
        sb.append(this.mOrig);
        sb.append("\n   Dir: ");
        sb.append(this.mDir);
        return sb.toString();
    }
    
}
